# -*- encoding:utf-8 -*-
from mako import runtime, filters, cache
UNDEFINED = runtime.UNDEFINED
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 5
_modified_time = 1292143922.9077899
_template_filename=u'/Users/joeldunham/old/onlinelinguisticdatabase/templates/base/javascriptDefs.html'
_template_uri=u'/base/javascriptDefs.html'
_template_cache=cache.Cache(__name__, _modified_time)
_source_encoding='utf-8'
from webhelpers.html import escape
_exports = ['checkForDuplicateTranscriptionScript', 'closeHelpDivScript', 'getMatchingLanguagesScript2', 'toggleLabelsJavaScript', 'getCharCodeScript', 'getMemoryContentsScript', 'labelsHidden', 'getToggleDivByTextInputScripts', 'translateOrthographyScript', 'fillHelpDivScript', 'graphToInputScript', 'getMatchingLanguagesScript']


def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        __M_writer = context.writer()
        # SOURCE LINE 5
        __M_writer(u'\n')
        # SOURCE LINE 39
        __M_writer(u'\n\n\n')
        # SOURCE LINE 56
        __M_writer(u'\n\n\n')
        # SOURCE LINE 67
        __M_writer(u'\n\n\n')
        # SOURCE LINE 81
        __M_writer(u'\n\n\n')
        # SOURCE LINE 111
        __M_writer(u'\n\n\n')
        # SOURCE LINE 121
        __M_writer(u'\n\n\n')
        # SOURCE LINE 242
        __M_writer(u'\n\n\n')
        # SOURCE LINE 273
        __M_writer(u'\n\n\n')
        # SOURCE LINE 324
        __M_writer(u'\n\n\n')
        # SOURCE LINE 368
        __M_writer(u'\n\n\n')
        # SOURCE LINE 382
        __M_writer(u'\n\n\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_checkForDuplicateTranscriptionScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 385
        __M_writer(u'\n ')
        # SOURCE LINE 389
        __M_writer(u'\n <script type="text/javascript">\n\n    function checkForDuplicateTranscription()\n    {\n       var duplicateWarningDiv = document.getElementById(\'duplicateWarningDiv\');\n       var responseSuccess = function(o) {\n           duplicateWarningDiv.style.display="block";\n           duplicateWarningDiv.style.visibility="visible";\n           duplicateWarningDiv.innerHTML = o.responseText;\n       };\n    \n       var responseFailure = function(o) {\n           pass;\n       };\n    \n       var callback = {\n         success:responseSuccess,\n         failure:responseFailure\n       };\n       \n       var transcription = document.getElementById(\'transcription\').value;\n       if (transcription)\n       {\n           var sUrl = \'/form/findduplicate/\' + transcription;\n           var transaction = YAHOO.util.Connect.asyncRequest(\'GET\', sUrl, callback, null);\n       }\n    }\n </script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_closeHelpDivScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 59
        __M_writer(u'\n<script type="text/javascript">\n function closeHelpDiv()\n {\n  helpDiv = document.getElementById(\'helpDiv\');\n  helpDiv.style.display="none";\n }\n</script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_getMatchingLanguagesScript2(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 114
        __M_writer(u'\n<script type="text/javascript">\n function getMatchingLanguages(sUrl, sourceID, targetID)\n {\n    alert(sUrl);\n }\n</script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_toggleLabelsJavaScript(context,targetClass='formTableRowLabel'):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 6
        __M_writer(u'\n<script type="text/javascript">\n(function() {\n    var targetClass = \'')
        # SOURCE LINE 9
        __M_writer(escape(targetClass))
        __M_writer(u'\';\n    var toggleRowLabels = function(e) {\n        var buttonID = \'toggleRowLabelsButton\';\n        var plusOrMinus = document.getElementById(buttonID).innerHTML;\n        var labels = YAHOO.util.Dom.getElementsByClassName(targetClass);\n        if(plusOrMinus==\'+\')\n        {\n            document.getElementById(buttonID).innerHTML = \'-\';\n            document.getElementById(buttonID).title = "hide labels"\n            for (i=0;i<labels.length;i++)\n            {\n                labels[i].style.display="block";\n                labels[i].style.display="visible";\n            } \n        }\n        else\n        {\n            document.getElementById(buttonID).innerHTML = \'+\';\n            document.getElementById(buttonID).title = "show labels"\n            for (i=0;i<labels.length;i++)\n            {\n                labels[i].style.display="none";\n            } \n        }\n    };\n\n    YAHOO.util.Event.on(\'toggleRowLabelsButton\', \'click\', toggleRowLabels);\n\n})();\n</script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_getCharCodeScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 276
        __M_writer(u'\n ')
        # SOURCE LINE 280
        __M_writer(u'\n <script type="text/javascript">\n    function pad(number, length)\n    {\n        while (number.length < length)\n        {\n            number = \'0\' + number;\n        }\n        return number;\n    }\n\n    function getCharCode(inputID, divID, compareID)\n    {\n        input = document.getElementById(inputID);\n        output = document.getElementById(divID);\n        compare = document.getElementById(compareID);\n        if (input.value != \'\')\n        {\n            var result = \'\'\n            for(i=0; i<input.value.length; i++)\n            {\n                var char = input.value.charCodeAt(i).toString(16).toUpperCase();\n                char = pad(char, 4);\n                result += \'U+\' + char + \' \';\n            }\n            result = result.trim();\n            if (compare.innerHTML.trim() == result)\n            {\n                var assess = \'&#x2713;\';\n                output.style.color = \'green\';\n            }\n            else\n            {\n                var assess = \'&#x2717;\';\n                output.style.color = \'red\';\n            }\n            output.innerHTML = assess + \' \' + result;\n        }\n        else\n        {\n            output.innerHTML = \'\'\n        }\n    }\n </script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_getMemoryContentsScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 84
        __M_writer(u'\n ')
        # SOURCE LINE 90
        __M_writer(u'\n<script type="text/javascript">\n function getMemoryContents(sUrl)\n {\n    var responseSuccess = function(o) {\n        content = document.getElementById(\'collectionContent\');\n        content.value += o.responseText;\n    };\n \n    var responseFailure = function(o) {\n        alert(\'failure\');\n    };\n \n    var callback = {\n      success:responseSuccess,\n      failure:responseFailure\n    };\n \n    var transaction = YAHOO.util.Connect.asyncRequest(\'GET\', sUrl, callback, null);\n }\n</script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_labelsHidden(context,targetClass='formTableRowLabel'):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 42
        __M_writer(u'\n<script type="text/javascript">\n(function() {\n    var targetClass = \'')
        # SOURCE LINE 45
        __M_writer(escape(targetClass))
        __M_writer(u'\';\n    var hide = function(e) {\n        var labels = YAHOO.util.Dom.getElementsByClassName(targetClass);\n        for (i=0;i<labels.length;i++)\n        {\n            labels[i].style.display="none";\n        } \n    };\n    window.onload = hide;\n})();\n</script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_getToggleDivByTextInputScripts(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 245
        __M_writer(u'\n ')
        # SOURCE LINE 250
        __M_writer(u'\n <script type="text/javascript">\n    function applyFuncToAll(func, divIDs)\n    {\n        for (i=0;i<divIDs.length;i++)\n        {\n            func(divIDs[i]);\n        } \n    }\n    \n    function divOn(divID)\n    {\n        div = document.getElementById(divID);\n        div.style.visibility=\'visible\';\n        div.style.display=\'block\';        \n    }\n    \n    function divOff(divID)\n    {\n        div = document.getElementById(divID);\n        div.style.display=\'none\';\n    }\n </script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_translateOrthographyScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 327
        __M_writer(u'\n ')
        # SOURCE LINE 332
        __M_writer(u'\n <script type="text/javascript">\n    function translateOrthography()\n    {\n        var inputOrthography = document.getElementById(\'inputOrthography\').value;\n        var outputOrthography = document.getElementById(\'outputOrthography\').value;\n        var input = document.getElementById(\'input\').value;\n        var outputorthographydiv = document.getElementById(\'outputorthographydiv\');\n        if (inputOrthography == outputOrthography)\n        {\n            outputorthographydiv.innerHTML = input;\n        }\n        else\n        {\n            getTranslation(input, inputOrthography, outputOrthography, outputorthographydiv);\n        }\n    }\n\n    function getTranslation(input, inputOrthography, outputOrthography, outputorthographydiv)\n    {\n       var responseSuccess = function(o) {\n           outputorthographydiv.innerHTML = o.responseText;\n       };\n    \n       var responseFailure = function(o) {\n           alert(\'failure\');\n       };\n    \n       var callback = {\n         success:responseSuccess,\n         failure:responseFailure\n       };\n       var sUrl = \'/settings/translate\' + \'?input=\' + input + \'&inputOrthography=\' + inputOrthography + \'&outputOrthography=\' + outputOrthography;\n       var transaction = YAHOO.util.Connect.asyncRequest(\'GET\', sUrl, callback, null);\n    }\n </script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_fillHelpDivScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 70
        __M_writer(u'\n<script type="text/javascript">\n function fillHelpDiv(helpContent)\n {\n  helpDiv = document.getElementById(\'helpDiv\');\n  helpDiv.style.display="block";\n  helpDiv.style.display="visible";\n  helpDivInner = document.getElementById(\'helpDivInner\');\n  helpDivInner.innerHTML = helpContent;\n }\n</script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_graphToInputScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 371
        __M_writer(u'\n ')
        # SOURCE LINE 373
        __M_writer(u'\n <script type="text/javascript">\n    function graphToInput(graph, inputId)\n    {\n        input = document.getElementById(inputId);\n        input.value += graph;\n        input.focus();\n    }\n </script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_getMatchingLanguagesScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 124
        __M_writer(u'\n ')
        # SOURCE LINE 129
        __M_writer(u'\n <script type="text/javascript">\n\n function getMatchingLanguages(sUrl, activeInputID, mode)\n {\n    var counterpartInputID = getLanguageCounterpartID(activeInputID);\n    var suggestionInputID = activeInputID + \'Suggestion\';\n    \n    var source = document.getElementById(activeInputID);\n    var counterpart = document.getElementById(counterpartInputID);\n    var target = document.getElementById(suggestionInputID);\n    \n    if ((mode==\'Id\' && source.value.length > 0) || source.value.length > 1)\n    {\n        YAHOO.util.Connect.abort();\n        var responseSuccess = function(o) {\n            xml = o.responseXML;\n            languages = xml.getElementsByTagName(\'language\');\n            msg = formatLanguagesAsOL(languages, activeInputID, counterpartInputID, mode);\n            target.innerHTML = msg; \n        };\n \n        var responseFailure = function(o) {\n            target.innerHTML = \'nothing\';\n        };\n \n        var callback = {\n          success:responseSuccess,\n          failure:responseFailure,\n          argument: activeInputID\n        };       \n        var uInput = escape(uni2ent(source.value));\n        sUrl = sUrl + \'?input=\' + uInput + \'&sourceID=\' + activeInputID + \'&mode=\' + mode;\n        var transaction = YAHOO.util.Connect.asyncRequest(\'GET\', sUrl, callback, null);\n    }\n }\n \n \n function copyToTarget(targetID, msg)\n {\n    target = document.getElementById(targetID);\n    target.value = msg;\n }\n \n \n function uni2ent(srcTxt) \n {\n    var entTxt = \'\';\n    var c, hi, lo;\n    var len = 0;\n    for (var i=0, code; code=srcTxt.charCodeAt(i); i++) {\n      var rawChar = srcTxt.charAt(i);\n      // needs to be an HTML entity\n      if (code > 255) {\n        // normally we encounter the High surrogate first\n        if (0xD800 <= code && code <= 0xDBFF) {\n          hi  = code;\n          lo = srcTxt.charCodeAt(i+1);\n          // the next line will bend your mind a bit\n          code = ((hi - 0xD800) * 0x400) + (lo - 0xDC00) + 0x10000;\n          i++; // we already got low surrogate, so don\'t grab it again\n        }\n        // what happens if we get the low surrogate first?\n        else if (0xDC00 <= code && code <= 0xDFFF) {\n          hi  = srcTxt.charCodeAt(i-1);\n          lo = code;\n          code = ((hi - 0xD800) * 0x400) + (lo - 0xDC00) + 0x10000;\n        }\n        // wrap it up as Hex entity\n        c = "&#x" + code.toString(16).toUpperCase() + ";";\n      }\n      else {\n        c = rawChar;\n      }\n      entTxt += c;\n      len++;\n    }\n    return entTxt;\n  } \n\n  function getLanguageCounterpartID(inputID){\n      if (inputID.slice(2) == \'Name\'){\n          return inputID.slice(0,2) + \'Id\';\n      }\n      else {\n          return inputID.slice(0,2) + \'Name\';\n      }\n  }\n    \n  function formatLanguagesAsOL(languages, sourceID, counterpartID, mode)\n  {\n    var msg = \'<ol>\';\n    for (i=0;i<languages.length;i++)\n    {\n        var Id = languages[i].getElementsByTagName(\'id\')[0].childNodes[0].nodeValue;\n        var Ref_Name = languages[i].getElementsByTagName(\'name\')[0].childNodes[0].nodeValue;\n        if (mode == \'Id\'){\n            var contentVisible = Id + \' (\' + Ref_Name + \')\';\n            var sourceFiller = Id;\n            var counterpartFiller = Ref_Name;\n        }\n        else {\n            var contentVisible = Ref_Name + \' (\' + Id + \')\';\n            var sourceFiller = Ref_Name;\n            var counterpartFiller = Id;\n        }\n        msg += \'<li class="suggestionList" onclick="copyToTarget(\\\'\' + sourceID + \'\\\', \\\'\' + sourceFiller + \'\\\'); copyToTarget(\\\'\' + counterpartID + \'\\\', \\\'\' + counterpartFiller + \'\\\'); divOff(\\\'\' + sourceID + \'Suggestion\\\');">\' + contentVisible + \'</li>\'\n    }\n    msg += \'</ol>\';\n    return msg;\n  }\n  \n </script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


